<%@page contentType="text/html; charset=utf-8"%>
<%@ include file="../inc/TagLibs.jsp"%>
<c:set var="pageTitle" value="外协商历史价格" />
<%@ include file="../inc/Title.jsp"%>
<head>
<link href="/css/Query.css" rel="stylesheet" type="text/css">
<link rel="stylesheet" type="text/css" href="/css/BillList.css" />
<script src="/js/QueryList.js"></script>
<script src="/js/popup_ext.js"></script>
<script language="javascript">
	function doSelect(index){
		var ob_arr = document.getElementsByName("query_checkbox");
		var arr=new Array();
		if (ob_arr.length>=index){
			var obj=ob_arr[index-1];
			arr[0]=new Array(obj.getAttribute("m_id"),obj.getAttribute("m_nam"),obj.getAttribute("p_id"),obj.getAttribute("p_nam"),obj.getAttribute("i_len"),obj.getAttribute("i_wid"),obj.getAttribute("i_spe"),obj.getAttribute("f_con"),obj.getAttribute("m_req"),obj.getAttribute("i_uni"),obj.getAttribute("i_amo"),obj.getAttribute("u_pri"),obj.getAttribute("s_num"),obj.getAttribute("i_cos"),"0","",obj.getAttribute("l_type"));
			parent.popRetVal=arr;
		}
		parent.ClosePop();
	}
	function doGo(pageIndex){
		var str=getSearchCondition();
		window.location="/cooper/CooperBillItemListForSelect.ihtm?"+str+"&current_page="+pageIndex;
	}
	function doJump(pageIndex){
		if(window.event.keyCode==13){
			doGo(pageIndex);
		}
	}
	function DoubleClick(it){
		var ob_arr = document.getElementsByName("query_checkbox");
		var arr=new Array();
		if(ob_arr.length>=it.getAttribute("index")){
			var obj=ob_arr[it.getAttribute("index")-1];
			arr[0]=new Array(obj.getAttribute("m_id"),obj.getAttribute("m_nam"),obj.getAttribute("p_id"),obj.getAttribute("p_nam"),obj.getAttribute("i_len"),obj.getAttribute("i_wid"),obj.getAttribute("i_spe"),obj.getAttribute("f_con"),obj.getAttribute("m_req"),obj.getAttribute("i_uni"),obj.getAttribute("i_amo"),obj.getAttribute("u_pri"),obj.getAttribute("s_num"),obj.getAttribute("i_cos"),"0","",obj.getAttribute("l_type"));
			parent.popRetVal=arr;
		}
		parent.ClosePop();
	}
	function doMutiSelect(){
		var ob_arr = document.getElementsByName("query_checkbox");
		var arr=new Array();
		for (i=0;i<ob_arr.length;i++){
			if ((ob_arr[i].checked == true)){
				arr.push(new Array(ob_arr[i].getAttribute("m_id"),ob_arr[i].getAttribute("m_nam"),ob_arr[i].getAttribute("p_id"),ob_arr[i].getAttribute("p_nam"),ob_arr[i].getAttribute("i_len"),ob_arr[i].getAttribute("i_wid"),ob_arr[i].getAttribute("i_spe"),ob_arr[i].getAttribute("f_con"),ob_arr[i].getAttribute("m_req"),ob_arr[i].getAttribute("i_uni"),ob_arr[i].getAttribute("i_amo"),ob_arr[i].getAttribute("u_pri"),ob_arr[i].getAttribute("s_num"),ob_arr[i].getAttribute("i_cos"),"0","",ob_arr[i].getAttribute("l_type")));
			}
		}
		if(arr.length>0){
			parent.popRetVal=arr;
			parent.ClosePop();
		}else{
			ShowAlert('提示框','请选择历史价格！',200,100);
			return;
		}
	}
	function doCancel(){
		parent.ClosePop();
	}
	function doInit(){
		//Window_Onload();
	}
	function checkInput(){
		if(window.event.keyCode==13){
			doSearch();
		}
	}
	function createPageParaStr(){
		var str="product_name="+encodeURIComponent(document.getElementById("product_name").value);
		str=str+"&content="+encodeURIComponent(document.getElementById("content").value);
		str=str+"&make_req="+encodeURIComponent(document.getElementById("make_req").value);
		str=str+"&mt_name="+encodeURIComponent(document.getElementById("mt_name").value);
		str=str+"&mt_id="+document.getElementById("mt_id").value;
		
		return str;
	}

	function createProgramParaStr(){
		var str="product_name="+encodeURIComponent(document.getElementById("hid_product_name").value);
		str=str+"&content="+encodeURIComponent(document.getElementById("hid_content").value);
		str=str+"&make_req="+encodeURIComponent(document.getElementById("hid_make_req").value);
		str=str+"&mt_name="+encodeURIComponent(document.getElementById("hid_mt_name").value);
		str=str+"&mt_id=${mtId}";
		
		return str;
	}
	function doSearch(){
		var str="id=${cooperatorId}&price_type=${priceType}&ts_id=${tsId}";
		if(IsAdvSearch){//高级
			str=str+"&search_type=1";
			if(document.getElementById("cb_pro").checked){
				var productName=document.getElementById("product_name").value.trim();
				if(productName==null || productName==""){
					ShowAlert('提示框','请输入材质',200,100);
					return;
				}
				str=str+"&cb_pro=1";
			}
			if(document.getElementById("cb_cont").checked){
				var content=document.getElementById("content").value.trim();
				if(content==null || content==""){
					ShowAlert('提示框','请输入成品内容',200,100);
					return;
				}
				str=str+"&cb_cont=1";
			}
			if(document.getElementById("cb_mr").checked){
				var makeReq=document.getElementById("make_req").value.trim();
				if(makeReq==null || makeReq==""){
					ShowAlert('提示框','请输入制作要求',200,100);
					return;
				}
				str=str+"&cb_mr=1";
			}
			if(document.getElementById("cb_mt").checked){
				var mtId=document.getElementById("mt_id").value;
				if(mtId==null || mtId=="" || mtId=="0"){
					ShowAlert('提示框','请选择项目类型',200,100);
					return;
				}
				str=str+"&cb_mt=1";
			}
		}else{//快速
			str=str+"&search_type=2";
		}
		var paraStr=createPageParaStr();
		if(paraStr!=""){
			str=str+"&"+paraStr;
		}
		window.location="/cooper/CooperBillItemListForSelect.ihtm?"+str;
	}
	function getSearchCondition(){
		var searchType="${searchType}";
		var str="id=${cooperatorId}&price_type=${priceType}&ts_id=${tsId}&search_type="+searchType;
		if(searchType=="1"){//高级
			<c:if test="${cbPro=='1'}">str=str+"&cb_pro=1";</c:if>
			<c:if test="${cbCont=='1'}">str=str+"&cb_cont=1";</c:if>
			<c:if test="${cbMr=='1'}">str=str+"&cb_mr=1";</c:if>
			<c:if test="${cbMt=='1'}">str=str+"&cb_mt=1";</c:if>
		}else{//快速
			
		}
		var paraStr=createProgramParaStr();
		if(paraStr!=""){
			str=str+"&"+paraStr;
		}
		return str;
	}
	function doAutoCheck(objId){
		document.getElementById(objId).checked=true;
	}
	function selectMakeType(){
		var url="/base/MakeTypeListForSelect.ihtm";
		ShowIframe("选择项目类型",url,310,500,"selectMakeTypeCallBack()");
	}
	function selectMakeTypeCallBack(){
		if(popRetVal!=null){
			document.getElementById("mt_id").value=popRetVal[0];
			document.getElementById("mt_name").value=popRetVal[1];
			doAutoCheck("cb_mt");
		}
	}
</script>
</head>
<body oncontextmenu="return false">
<div class="Wrap"><!-- 页面主框架 -->
    
	<div id="ListContainer" class="Container"><!-- 主体容器 -->
	    
	    <!-- 标题栏 -->
	    <div class="Heading BillIcon">
	        <div class="HeadingContent">
	            <h1>外协商历史价格</h1>
	            <span class="Note">可以选择之前交易的产品价格，直接作为新单的价格</span>
	        </div>
	    </div>
	
		<!-- 主内容 -->
		<div class="Content">
	        <!-- 筛选控件栏 -->
	        <div class="FilterBar ClearFix">
	            <div class="SearchIcon"></div>
	            <span class="fl">
	            	<table class="MoreOption" cellpadding="0" cellspacing="0">
	            		<th class="c1" width="80px">
	            			<input type="checkbox" name="cb_mt" id="cb_mt" <c:if test="${cbMt=='1' || searchType=='2'}">checked="true"</c:if> style="visibility:hidden;" />
	            			项目类型
	            		</th>
	            		<td class="c1" width="260px">
	            			<input type="text" class="TextBox readonly" readonly="true" name="mt_name" id="mt_name" value="<c:out value="${mtName}" />" >
							<img class="imgIconButton" src="/images/make-a.gif" onClick="selectMakeType();" />
							<input type="hidden" id="hid_mt_name" value="<c:out value="${mtName}" />">
							<input type="hidden" name="mt_id" id="mt_id" value="${mtId}">
	            		</td>
	            	</table>
	            </span>
				<span class="fr">
	            	<a href="javascript:;" id="lnkMoreOption">更多查询选项</a>
		  			<input type="button" value=" 查 询" onClick="doSearch();" class="buttom search-but" id="sSearchButton" name="sSearchButton">
		  			<input type="button" value=" 选 择" onClick="doMutiSelect();" id="sSelectButton" name="sSelectButton" class="buttom search-select">
	            </span>
				<div id="dvMoreOptionBox" class="MoreOptionBox" style="display:none;">
					<table class="MoreOption" cellpadding="0" cellspacing="0">
						<tr>
							<th class="c1" width="80px">
			        			<input type="checkbox" name="cb_cont" id="cb_cont" <c:if test="${cbCont=='1'}">checked="true"</c:if>>
			        			成品内容
			        		</th>
			    			<td class="c1" width="240px">
			        			<input type="text" class="TextBox" name="content" id="content" onKeyUp="checkInput();" onFocus="doAutoCheck('cb_cont');" value="<c:out value="${content}" />" >
								<input type="hidden" id="hid_content" value="<c:out value="${content}" />">
			    			</td>
			    		</tr>
			    		<tr>
			    			<th class="c1">
			        			<input type="checkbox" name="cb_mr" id="cb_mr" <c:if test="${cbMr=='1'}">checked="true"</c:if>>
			        			制作要求
			        		</th>
			    			<td class="c1">
			        			<input type="text" class="TextBox" name="make_req" id="make_req" onKeyUp="checkInput();" onFocus="doAutoCheck('cb_mr');" value="<c:out value="${makeReq}" />" >
								<input type="hidden" id="hid_make_req" value="<c:out value="${makeReq}" />">
			    			</td>
			    		</tr>
			    		<tr>
			    			<th class="c1">
			        			<input name="" type="checkbox" name="cb_pro" id="cb_pro" <c:if test="${cbPro=='1'}">checked="true"</c:if> />
			        			材质
			        		</th>
			    			<td class="c1">
			        			<input type="text" class="TextBox" id="product_name" name="product_name" onKeyUp="checkInput();" onFocus="doAutoCheck('cb_pro');" value="<c:out value="${productName}" />" >
								<input type="hidden" id="hid_product_name" value="<c:out value="${productName}" />">
			    			</td>
			    		</tr>
			    	</table>
					
					<div class="OptionOrderBy">
						<span class="fr"><a href="javascript:;" id="lnkHiddenOption">隐藏查询选项</a></span>
	                </div>
				</div>
			</div>
			
			<!-- 提示信息显示栏 -->
	        <div class="MsgBar">
	            <%@include file="../inc/AlertMsg.jsp"%>
	        </div>

		    <div class="table-list">
		        <table width="100%">
					<c:if test="${priceType=='AREA'}">
					<tr>
						<th width="14"><input type="checkbox" onClick="javascript:checkall(this);"></th>
						<th width="9%" >订货日期</th>
						<th width="10%" >项目类型</th>
						<th width="12%" >内容</th>
						<th width="14%" >材质</th>
						<th width="12%" >规格</th>
						<th width="16%" >制作要求</th>
						<th width="5%" >数量</th>
						<th width="5%" >平方数</th>
						<th width="6%" >元/平方</th>
						<th width="7%" >金额</th>
						<th width="4%" >操作</th>
					</tr>
					</c:if>
					<c:if test="${priceType=='AMOUNT'}">
					<tr>
						<th width="14"><input type="checkbox" onClick="javascript:checkall(this);"></th>
						<th width="9%" >订货日期</th>
						<th width="10%" >项目类型</th>
						<th width="12%" >内容</th>
						<th width="14%" >材质</th>
						<th width="12%" >规格</th>
						<th width="16%" >制作要求</th>
						<th width="5%" >单位</th>
						<th width="5%" >数量</th>
						<th width="6%" >单价</th>
						<th width="7%" >金额</th>
						<th width="4%" >操作</th>
					</tr>
					</c:if>
					<c:if test="${priceType=='LENGTH'}">
					<tr>
						<th width="14"><input type="checkbox" onClick="javascript:checkall(this);"></th>
						<th width="9%" >订货日期</th>
						<th width="10%" >项目类型</th>
						<th width="12%" >内容</th>
						<th width="14%" >材质</th>
						<th width="12%" >规格</th>
						<th width="16%" >制作要求</th>
						<th width="5%" >数量</th>
						<th width="5%" >总长度</th>
						<th width="6%" >单价</th>
						<th width="7%" >金额</th>
						<th width="4%" >操作</th>
					</tr>
					</c:if>
					<c:forEach var="item" items="${qr.list}" varStatus="i">
					<c:if test="${(i.index mod 2)==0}"><c:set var="trClass" value="query_list_data_tr1" /></c:if>
					<c:if test="${(i.index mod 2)!=0}"><c:set var="trClass" value="query_list_data_tr2" /></c:if>
					<tr class="${trClass}" index="${i.index+1}" style='cursor:pointer;' ondblclick='javascript:DoubleClick(this)' onClick='javascript:ClickCheck(this,true)' onmouseout='javascript:mouseout(this)' onmouseover='javascript:mouseover(this)'>
						<td ><input type="checkbox" onClick="javascript:ClickCheck(this,true);" name='query_checkbox' m_id="${item[1].cooperBillItem.makeTypeId}" m_nam="<c:out value="${item[1].makeTypeName}" />" p_id="${item[1].cooperBillItem.proId}" p_nam="<c:out value="${item[1].cooperBillItem.proName}" />" i_len='<commonTag:parseBigDecimal source="${item[1].cooperBillItem.length}" />' i_wid='<commonTag:parseBigDecimal source="${item[1].cooperBillItem.width}" />' i_spe="<c:out value="${item[1].cooperBillItem.specification}" />" f_con="<c:out value="${item[1].cooperBillItem.finishedContent}" />" m_req="<c:out value="${item[1].cooperBillItem.makeRequire}" />" i_uni="<c:out value="${item[1].cooperBillItem.unit}" />" i_amo='<commonTag:parseBigDecimal source="${item[1].cooperBillItem.amount}" />' u_pri='<commonTag:parseBigDecimal source="${item[1].cooperBillItem.unitPrice}" />' s_num='<commonTag:parseBigDecimal source="${item[1].cooperBillItem.squareNum}" />' i_cos='<commonTag:parseBigDecimal source="${item[1].cooperBillItem.cost}" />' l_type='${item[1].cooperBillItem.lengType}'></td>
						<td class="ListTd"><fmt:formatDate value="${item[0].cooperDate}" pattern="yyyy-MM-dd"/></td>
						<td>${item[1].makeTypeName}</td>
						<td>${item[1].cooperBillItem.finishedContent}</td>
						<td>${item[1].cooperBillItem.proName}</td>
						<td>${item[1].cooperBillItem.specification}</td>
						<td>${item[1].cooperBillItem.makeRequire}</td>
						<c:if test="${priceType=='AREA' || priceType=='LENGTH'}">
							<td>${item[1].cooperBillItem.amount}</td>
							<td>
								${item[1].cooperBillItem.squareNum}
								<c:if test="${priceType=='LENGTH'}"><c:if test="${item[1].cooperBillItem.lengType=='M'}">米</c:if><c:if test="${item[1].cooperBillItem.lengType=='CM'}">公分</c:if></c:if>
							</td>
						</c:if>
						<c:if test="${priceType=='AMOUNT'}">
							<td>${item[1].cooperBillItem.unit}</td>
							<td>${item[1].cooperBillItem.amount}</td>
						</c:if>
						<td>${item[1].cooperBillItem.unitPrice}</td>
						<td>${item[1].cooperBillItem.cost}</td>
						<td>
							<a href="javascript:doSelect('${i.index+1}');">选择</a>
						</td>
					</tr>
					</c:forEach>
				</table>
				<c:set var="showPagesSelectButton" value="Y" />
				<c:set var="pagesSelectButtonFun" value="doMutiSelect()" />
			</div>

			<!-- 底栏 分页、操作等 -->
	        <div class="BottomToolBar ClearFix">
			    <%@include file="../inc/Pages.jsp"%>
	        </div>
			
		</div>
	</div>

</div>
</body>
</html>
<script type="text/javascript">
	function ChangeWindowSize( container, maxWidth ){
	    setTimeout( function(){
	        var w1 = document.documentElement.clientWidth-40;
	        if( w1>maxWidth ) w1 = maxWidth;
	        else if( w1<970 ) w1 = 960;
	        container.style.width = w1+'px';
	    }, 300 );
	}
	var IsAdvSearch = false;
	(function(){
		doInit();
	    var ListContainer = document.getElementById('ListContainer');
	    ChangeWindowSize( ListContainer, 2020 );    // 超过 1280 的最大 1260 ，不全部铺满
	
	    var lnkMoreOption   = document.getElementById('lnkMoreOption');
	    var lnkHiddenOption = document.getElementById('lnkHiddenOption');
	    lnkMoreOption.onclick = function(){
	    	IsAdvSearch = true;
	        document.getElementById('dvMoreOptionBox').style.display = 'block';
	        document.getElementById('cb_mt').style.visibility = 'visible';
	        this.style.visibility = 'hidden';
	    };
	    lnkHiddenOption.onclick = function(){
	    	IsAdvSearch = false;
	        document.getElementById('dvMoreOptionBox').style.display = 'none';
	        document.getElementById('cb_mt').style.visibility = 'hidden';
	        lnkMoreOption.style.visibility = 'visible';
	    };
	})();
</script>
